package com.symc.sims0213xfw.service.impl;

import com.symc.sims0213xfw.bean.User;
import com.symc.sims0213xfw.dao.impl.UserDaoImpl;
import com.symc.sims0213xfw.service.UserService;

import java.sql.SQLException;

/**
 * @Author: 凤文  沈阳医学院2019级医学信息工程 0213
 * @CreateTime: 2022/01/16 10:44
 * @Description:
 */
public class UserServiceImpl implements UserService {
    private UserDaoImpl userDao = new UserDaoImpl();

    @Override
    public String registerNewUserMessage(String uname, String upassword) {
        int i = 0;
        try {
            if (!userDao.queryUserPrimaryKey(uname)) {
                i = userDao.insertUser(uname, upassword);
                if (i > 0) {
                    return "注册成功！";
                }else {
                    return "注册失败！";
                }
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return "该用户已经被注册";
    }

    @Override
    public User getUserFromDB(String uname) {
        return userDao.getUser(uname);
    }

}